




/*
*************************************************************************
*西瑞克斯研发管理系统
*版 本: 1.0   
*日 期：02/16/2012    
*作 者： 王浩 QQ：873987060   
*************************************************************************   
*/ 
package com.application.yfprojectplan.struts.actions;
import java.io.File;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.application.attachment.entity.Attachment;
import com.application.attachment.service.AttachmentService;
import com.application.attachment.struts.form.AttachmentForm;
import com.application.usertable.entity.Usertable;
import com.application.yfexamine.entity.YfExmaine;
import com.application.yfexamine.service.YfExmaineService;
import com.application.yfexamine.struts.form.YfExmaineForm;
import com.application.yfprojectapproval.entity.YfProjectApproval;
import com.application.yfprojectapproval.struts.form.YfProjectApprovalForm;
import com.application.yfprojectplan.commons.Constants;
import com.application.yfprojectplan.entity.YfProjectPlan;
import com.application.yfprojectplan.entity.YfProjectPlanItem;
import com.application.yfprojectplan.service.YfProjectPlanService;
import com.application.yfprojectplan.struts.form.YfProjectPlanForm;
import com.manager.commons.CommonUtil;
import com.manager.commons.DisplayTagPageBean;
import com.manager.commons.RandomKey;
import com.manager.commons.page.PageBean;
import com.manager.workflow.WorkFlowConstants;
import com.manager.workflow.core.WorkFlowCommon;
import com.manager.workflow.core.YfWorkFlowDefine;
 /**
 * 
 * Description:YfProjectPlanAction<br />
 * 
 * Version:V0.1<br />
 * 
 * Author: 王浩 QQ：873987060    <br />
 * 
 * History: <br />
 * 
 * 02/16/2012 
 * 
 */
public class YfProjectPlanAction extends DispatchAction
{
       
       /**
	 * Service层实例
	 */
	private YfProjectPlanService yfProjectPlanService;
	
	private AttachmentService attachmentService;

	private WorkFlowCommon workFlowCommon;
	
	private YfExmaineService yfExmaineService;
	
	/**
	 * 日志
	 */
	private Logger log = Logger.getLogger(this.getClass());

	/**
	 * 实体对象
	 */
    private YfProjectPlan yfProjectPlan;


        /**
	 * 采用partialList方式分页程序
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public ActionForward getYfProjectPlanPartialList(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("searchYfProjectPlan" + "开始");
		YfProjectPlanForm yfProjectPlan = (YfProjectPlanForm)form;
		// 统计总记录数的sql语句
		int resultSize = 0;
		// 初始化pageBean供分页所用
		PageBean pageBean = null;
		// 取得当前页list数据
		List yfProjectPlanList = null;
		resultSize = yfProjectPlanService.getAllCountYfProjectPlan(yfProjectPlan);
		pageBean = PageBean.getPageBean("yfProjectPlanTab", resultSize,request);
		yfProjectPlanList = yfProjectPlanService.searchYfProjectPlan(yfProjectPlan,pageBean);
		request.setAttribute("yfProjectPlanList", yfProjectPlanList);
		request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
		log.debug("searchYfProjectPlan" + "结束");

		return mapping.findForward(Constants.SUCCESS);
	}

        /**
	 * 到达新增页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toAddYfProjectPlan(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("toAddYfProjectPlans");
		YfProjectPlanForm yfProjectPlanForm = (YfProjectPlanForm) form;
		yfProjectPlanForm.setId(RandomKey.generateID_Long_19());
		yfProjectPlanForm.setRname(CommonUtil.getCurrentUser(request).getRname());
		yfProjectPlanForm.setProjectManager(CommonUtil.getCurrentUser(request).getId());
		request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
		return mapping.findForward(Constants.SUCCESS);
	}
	
	public ActionForward changeYfProjectPlan(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("changeYfProjectPlan");
		YfProjectPlanForm yfProjectPlanForm = (YfProjectPlanForm) form;
		yfProjectPlan = yfProjectPlanService.searchYfProjectPlan(yfProjectPlanForm, null).get(0);
		yfProjectPlan.setPlanType("2");
		
		yfProjectPlanForm.setProjectNo(yfProjectPlan.getProjectNo());
		YfProjectPlan maxTemp = (YfProjectPlan) yfProjectPlanService.searchYfProjectPlanMax(yfProjectPlanForm, null).get(0);
		yfProjectPlan.setChangeCdate(maxTemp.getChangeCdate());
		request.setAttribute(Constants.YFPROJECTPLAN, yfProjectPlan);
		yfProjectPlanForm.setId(RandomKey.generateID_Long_19());
		yfProjectPlanForm.setRname(CommonUtil.getCurrentUser(request).getRname());
		yfProjectPlanForm.setProjectManager(CommonUtil.getCurrentUser(request).getId());
		request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
		return mapping.findForward("success");
	}

 
	public ActionForward addYfProjectChangePlan(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("addYfProjectChangePlan");
		YfProjectPlan yfProjectPlan = this.getYfProjectPlan(form);
		yfProjectPlan.setAuditStatus(WorkFlowConstants.AUDIT_STATUS_1);
		 yfProjectPlan.setOperateid(CommonUtil.getCurrentUser(request).getId());
		 yfProjectPlan.setCreateDate(new Date());
		this.yfProjectPlanService.insertObject(yfProjectPlan);
		return mapping.findForward("listchange");
	}
	
	
	/**
	 * 增加
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward addYfProjectPlan(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("addYfProjectPlans");
		YfProjectPlan yfProjectPlan = this.getYfProjectPlan(form);
		yfProjectPlan.setAuditStatus(WorkFlowConstants.AUDIT_STATUS_1);
		 yfProjectPlan.setOperateid(CommonUtil.getCurrentUser(request).getId());
		 yfProjectPlan.setCreateDate(new Date());
		this.yfProjectPlanService.insertObject(yfProjectPlan);
		addProjectWorkSheetsPlan(request,yfProjectPlan.getId());
		return mapping.findForward(Constants.SUCCESS);
	}
    
	private void addProjectWorkSheetsPlan(HttpServletRequest request, String planId) throws Exception {
		YfProjectPlanItem yfProjectPlanItem = null;
		Map parmMap = request.getParameterMap();
		Iterator it = parmMap.entrySet().iterator();
		Map yfProjectPlanItemMap = new HashMap();
		while (it.hasNext()) {
			Map.Entry entry = (Entry) it.next();
			String key = (String) entry.getKey();
			if(key.indexOf("*") < 0 || key.indexOf("plan") < 0) {
				continue;
			}
			String value = ((String[]) entry.getValue())[0];
			String pre = key.substring(0, key.indexOf("*"));
			String property = key.substring(key.indexOf("*") + 1);
			if(yfProjectPlanItemMap.containsKey(pre)) {
				yfProjectPlanItem = (YfProjectPlanItem) yfProjectPlanItemMap.get(pre);
				BeanUtils.setProperty(yfProjectPlanItem, property, value);
			} else {
				yfProjectPlanItem = new YfProjectPlanItem();
				BeanUtils.setProperty(yfProjectPlanItem, property, value);
				yfProjectPlanItemMap.put(pre, yfProjectPlanItem);
			}

		}
		Iterator its = yfProjectPlanItemMap.values().iterator();
		long i = 0;
		while (its.hasNext()) {
			yfProjectPlanItem = (YfProjectPlanItem) its.next();
			yfProjectPlanItem.setPlanId(planId);
			yfProjectPlanItem.setOrderNo(i);
			yfProjectPlanItem.setId(RandomKey.generateID_Long_19());
			yfProjectPlanItem.setOperateid(CommonUtil.getCurrentUser(request).getId());
			yfProjectPlanItem.setCreateDate(new Date());
			this.yfProjectPlanService.insertObject(yfProjectPlanItem);
			i++;
		}
	}
	
	/**
	 * 删除
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward deleteYfProjectPlan(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("deleteYfProjectPlans");
		YfProjectPlanForm yfProjectPlanForm = (YfProjectPlanForm) form;
		this.yfProjectPlanService.deleteYfProjectPlans(yfProjectPlanForm);
		yfProjectPlanService.deleteYfProjectPlanItems(yfProjectPlanForm.getId());
		String serverPath=CommonUtil.ATTACHE_FILE;
		if(StringUtils.isBlank(serverPath)){
			serverPath=request.getSession().getServletContext().getRealPath("/"); 
		}
		AttachmentForm attachmentForm = new AttachmentForm();
		attachmentForm.setFid(yfProjectPlanForm.getId().toString());
		attachmentForm.setType(com.manager.commons.Constants.FJ_TYPE_XMJH);
		List<Attachment> attachment = attachmentService.queryAttachment(attachmentForm);
		if(attachment!=null && attachment.size()>0){
			for (Attachment attachment2 : attachment) {
				File file = new File(serverPath + attachment2.getUrl());
		        file.delete();
				attachmentService.deleteObject(attachment2);
				
			}
		}
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 到达更新页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toUpdateYfProjectPlan(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("toUpdateYfProjectPlans");

		YfProjectPlanForm yfProjectPlanForm = (YfProjectPlanForm) form;
		yfProjectPlan = this.yfProjectPlanService.searchYfProjectPlan(yfProjectPlanForm,null).get(0);
		request.setAttribute(Constants.YFPROJECTPLAN, yfProjectPlan);
		request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
		if("2".equals(yfProjectPlan.getPlanType())){
			return mapping.findForward("change");
		}
		List planItems = yfProjectPlanService.getYfProjectPlanItems(yfProjectPlan.getId());
		request.setAttribute("workPlanList", planItems);
		request.setAttribute("workPlanCount", planItems == null ? 0 : planItems.size());
		return mapping.findForward(Constants.SUCCESS);
	}

        
	/**
	 * 更新
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward updateYfProjectPlan(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("updateYfProjectPlans");
		YfProjectPlan yfProjectPlan = this.getYfProjectPlan(form);
	    yfProjectPlan.setOperateid(CommonUtil.getCurrentUser(request).getId());
		 yfProjectPlan.setCreateDate(new Date());
		this.yfProjectPlanService.updateObject(yfProjectPlan);
		yfProjectPlanService.deleteYfProjectPlanItems(yfProjectPlan.getId());
		addProjectWorkSheetsPlan(request,yfProjectPlan.getId());
		return mapping.findForward(Constants.SUCCESS);
	}
        
	/**
	 * 查看页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward viewYfProjectPlan(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		log.debug("viewYfProjectPlan");

		YfProjectPlanForm yfProjectPlanForm = (YfProjectPlanForm) form;
		yfProjectPlan = this.yfProjectPlanService.searchYfProjectPlan(yfProjectPlanForm,null).get(0);
		request.setAttribute(Constants.YFPROJECTPLAN, yfProjectPlan);
		String processId = yfProjectPlan.getProcessId();
		if (StringUtils.isNotBlank(processId)) {
			examineList(yfProjectPlan.getProcessId(),yfExmaineService,request);
		}
		request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
		if("2".equals(yfProjectPlan.getPlanType())){
			return mapping.findForward("change");
		}
		List planItems = yfProjectPlanService.getYfProjectPlanItems(yfProjectPlan.getId());
		request.setAttribute("workPlanList", planItems);
		request.setAttribute("workPlanCount", planItems == null ? 0 : planItems.size());
		
		return mapping.findForward(Constants.SUCCESS);
	}

	// get--set
	/**
	 * @return the YfProjectPlanService
	 */
	public YfProjectPlanService getYfProjectPlanService() {
		return this.yfProjectPlanService;
	}

	/**
	 * @param YfProjectPlanService
	 *  the YfProjectPlanService to set
	 */
	public void setYfProjectPlanService(YfProjectPlanService yfProjectPlanService) {
		this.yfProjectPlanService = yfProjectPlanService;
	}

	/**
	 * 获取YfProjectPlan实体
	 * @param ActionForm
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 * @return the YfProjectPlan
	 */
	public YfProjectPlan getYfProjectPlan(ActionForm form) throws IllegalAccessException, InvocationTargetException {
		YfProjectPlanForm yfProjectPlanForm = (YfProjectPlanForm) form;
		yfProjectPlan = new YfProjectPlan();
		BeanUtils.copyProperties(yfProjectPlan, yfProjectPlanForm);
		return yfProjectPlan;
	}
    
        public void setYfProjectPlan(YfProjectPlan yfProjectPlan) {
		this.yfProjectPlan = yfProjectPlan;
	}

		public AttachmentService getAttachmentService() {
			return attachmentService;
		}

		public void setAttachmentService(AttachmentService attachmentService) {
			this.attachmentService = attachmentService;
		}
		/**
		 * 提交审核
		 * 
		 * @param mapping
		 * @param form
		 * @param request
		 * @param response
		 * @return ActionForward
		 * @throws Exception
		 */
		public ActionForward submitWorkFlowYfProjectPlan(ActionMapping mapping, ActionForm form,
				HttpServletRequest request, HttpServletResponse response)
				throws Exception {
			log.debug("submitWorkFlowYfProjectPlan");
			String submitType = request.getParameter("submitType");
			//新增界面直接提交
			if(StringUtils.isNotBlank(submitType) && "add".equals(submitType)){
				yfProjectPlan = this.getYfProjectPlan(form);
				yfProjectPlan.setOperateid(CommonUtil.getCurrentUser(request).getId());
				yfProjectPlan.setCreateDate(new Date());
				this.yfProjectPlanService.insertObject(yfProjectPlan);
				addProjectWorkSheetsPlan(request,yfProjectPlan.getId());
			}
			if(StringUtils.isNotBlank(submitType) && "update".equals(submitType)){
				yfProjectPlan = this.getYfProjectPlan(form);
				YfProjectPlanForm tempForm = new YfProjectPlanForm();
				tempForm.setId(yfProjectPlan.getId());
				YfProjectPlan old = yfProjectPlanService.searchYfProjectPlan(tempForm,null).get(0);
				yfProjectPlan.setProjectType(old.getProjectType());
				yfProjectPlan.setProjectOrg(old.getProjectName());
				yfProjectPlanService.deleteYfProjectPlanItems(yfProjectPlan.getId());
				addProjectWorkSheetsPlan(request,yfProjectPlan.getId());
				
			}else{
				YfProjectPlanForm yfProjectPlanForm = (YfProjectPlanForm) form;
				yfProjectPlan = yfProjectPlanService.searchYfProjectPlan(yfProjectPlanForm,null).get(0);
			}
			Map<String,String> mapVar = new HashMap<String,String>();
			mapVar.put("bussId", yfProjectPlan.getId().toString());
			if("1".equals(yfProjectPlan.getPlanType())){  //原计划
				mapVar.put("bussType", WorkFlowConstants.BUSS_TYPE_XMJH.toString());
			}
			if("2".equals(yfProjectPlan.getPlanType())){  //变更计划
				mapVar.put("bussType", WorkFlowConstants.BUSS_TYPE_XMJH_BG.toString());
			}
			
			mapVar.put("projectName", yfProjectPlan.getProjectName().toString());
			mapVar.put("projectType", yfProjectPlan.getProjectType().toString());
			mapVar.put("projectOrg", yfProjectPlan.getProjectOrg().toString());
			mapVar.put("projectNo", yfProjectPlan.getProjectNo().toString());
			mapVar.put("ownYear","0");  //外协合同 暂时不放  
			CommonUtil.putMapVar(request,mapVar);
			 
			String processId = workFlowCommon.startFlow(WorkFlowConstants.PORCESS_DEFINITION_ONE,CommonUtil.getCurrentUser(request).getId(),mapVar);
		
			yfProjectPlan.setProcessId(processId);
			yfProjectPlan.setAuditStatus(WorkFlowConstants.AUDIT_STATUS_2);
			yfProjectPlan.setOperateid(CommonUtil.getCurrentUser(request).getId());
//			yfProjectPlan.setCreateDate(new Date());
			this.yfProjectPlanService.updateObject(yfProjectPlan);
			return mapping.findForward(Constants.SUCCESS);
		}

		
		/**
		 * 进入审核页面
		 * @param mapping
		 * @param form
		 * @param request
		 * @param response
		 * @return ActionForward
		 * @throws Exception
		 */
		public ActionForward toAuditYfProjectPlan(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
			log.debug("toAuditYfProjectPlan");
			YfProjectPlanForm yfProjectPlanForm = (YfProjectPlanForm) form;
			String bussId = request.getParameter("bussId");
			String processId = request.getParameter("processId");
			String workItemId = request.getParameter("workItemId");
			String auditRole = request.getParameter("auditRole");
			String bussType = request.getParameter("bussType");
			request.setAttribute("auditRole", auditRole);
			request.setAttribute("bussType",bussType);
			yfProjectPlanForm.setId(bussId);
			yfProjectPlan = yfProjectPlanService.searchYfProjectPlan(yfProjectPlanForm,null).get(0);
			yfProjectPlan.setWorkItemId(workItemId);
			request.setAttribute(Constants.YFPROJECTPLAN, yfProjectPlan);
			examineList(processId,yfExmaineService,request);
			request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
			if("2".equals(yfProjectPlan.getPlanType())){
				return mapping.findForward("change");
			}
			List planItems = yfProjectPlanService.getYfProjectPlanItems(yfProjectPlan.getId());
			request.setAttribute("workPlanList", planItems);
			request.setAttribute("workPlanCount", planItems == null ? 0 : planItems.size());
			
			return mapping.findForward(Constants.SUCCESS);
		}
		
		
		/**
		 * 处理审批 提交流程
		 * @param mapping
		 * @param form
		 * @param request
		 * @param response
		 * @return
		 * @throws Exception
		 */
		public ActionForward commandFlowYfProjectPlan(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
			log.debug("commandFlowYfProjectPlan");
			YfProjectPlanForm yfProjectPlanForm = (YfProjectPlanForm) form;
			yfProjectPlan = yfProjectPlanService.searchYfProjectPlan(yfProjectPlanForm,null).get(0);
			YfExmaine examine = addYfExmaine(yfProjectPlanForm,request);
			Map processVar = new HashMap();
			//不为打回修改完成后提交
			if(!examine.getExamineFlag().equals("modify")){
				yfExmaineService.insertObject(examine);
				if(examine.getExamineFlag().equals(WorkFlowConstants.AUDIT_STATUS_AGREE)){
					processVar.put("approveFlag","agree");
					Usertable user = (Usertable) request.getSession().getAttribute("loginUser");
					String roleName = user.getRoleList().get(0).getName();
					if(roleName.equals(WorkFlowConstants.ROLE_FGFZ)){
						yfProjectPlan.setAuditStatus(WorkFlowConstants.AUDIT_STATUS_3);
						yfProjectPlanService.updateObject(yfProjectPlan);
					}
				}else if(examine.getExamineFlag().equals(WorkFlowConstants.AUDIT_STATUS_DISAGREE)){
					processVar.put("approveFlag","disagree");
					yfProjectPlan.setAuditStatus(WorkFlowConstants.AUDIT_STATUS_4);
					yfProjectPlanService.updateObject(yfProjectPlan);
				}
			}
			
			
			processVar.put("bussId", yfProjectPlan.getId().toString());
			if("1".equals(yfProjectPlan.getPlanType())){  //原计划
				processVar.put("bussType", WorkFlowConstants.BUSS_TYPE_XMJH.toString());
			}
			if("2".equals(yfProjectPlan.getPlanType())){  //变更计划
				processVar.put("bussType", WorkFlowConstants.BUSS_TYPE_XMJH_BG.toString());
			}
			processVar.put("projectName", yfProjectPlan.getProjectName().toString());
			processVar.put("projectType", yfProjectPlan.getProjectType().toString());
			processVar.put("projectOrg", yfProjectPlan.getProjectOrg().toString());
			processVar.put("projectNo", yfProjectPlan.getProjectNo().toString());
			processVar.put("ownYear", "0");
			processVar.put("yfbussTaskType",WorkFlowConstants.BUSS_TASK_TYPE_NORMAL);
			
			/**
			 * 打回修改后需要提交  根据角色决定流程路径
			 */
			CommonUtil.putMapVar(request,processVar);
			processVar.put("yfbussTaskType",WorkFlowConstants.BUSS_TASK_TYPE_NORMAL);
			String workItemId = yfProjectPlanForm.getWorkItemId();
			if(examine.getExamineFlag().equals(WorkFlowConstants.AUDIT_STATUS_REBACK)){
				processVar.put("yfbussTaskType",WorkFlowConstants.BUSS_TASK_TYPE_REBACK);
				//如果记录operatorid 人  的角色为研发经理的时候，回退就需要跳过研发经理审批  流程开始的参数须为 START_YFJL
//				workFlowCommon.commandFlowReback(workItemId, processVar,START_YFJL);
				String operateId = yfProjectPlan.getOperateid();
				if(CommonUtil.isYFJL(operateId)){
					workFlowCommon.commandFlowReback(workItemId, processVar,YfWorkFlowDefine.START_YFJL);
				}else{
				    workFlowCommon.commandFlowReback(workItemId, processVar);
				}
			}else{
				workFlowCommon.commandFlow(workItemId, processVar);
			}
			return mapping.findForward(Constants.SUCCESS);
		}
		
		/**
		 * Description: TODO 组合审批意见对象,添加
		 * 
		 * @param form
		 * @param request
		 * @return ActionForward
		 */
		public YfExmaine addYfExmaine(ActionForm form, HttpServletRequest request) {

			YfProjectPlanForm yfProjectPlanForm = (YfProjectPlanForm) form;
			// 审核标识
			String examineFlag = yfProjectPlanForm.getExamineFlag();
			// 审核意见
			String examineOption = yfProjectPlanForm.getExamineOption();
			String processId = yfProjectPlanForm.getProcessId();
			YfExmaine yfExmaine = new YfExmaine();
			 
			yfExmaine.setId(RandomKey.generateID_Long_19());
			yfExmaine.setExamineFlag(examineFlag);
			yfExmaine.setExamineOption(examineOption);
			yfExmaine.setProcessId(processId);
			yfExmaine.setExamineDate(new Date());
			if(request.getSession().getAttribute("loginUser")!=null){
				Usertable curUser = (Usertable) request.getSession().getAttribute("loginUser");
				yfExmaine.setExaminePerson(curUser.getRname());
				if(curUser.getRoleList().size()>1){
					String roleName = workFlowCommon.getRoleNameByActivityId(yfProjectPlanForm.getWorkItemId());
					yfExmaine.setExamineOrg(roleName);
				}else{
					yfExmaine.setExamineOrg(curUser.getRoleList().get(0).getName()); //无法处理同一个人有多个审批角色
				}
				
			}
			return yfExmaine;
		}
		
		 /*
		 * Description: TODO 查看显示意见
		 * 
		 * @param processInsId
		 * @param examine
		 * @param examineService
		 * @param examineLis
		 * @param request
		 *        void
		 */
		public void examineList(String processInsId, YfExmaineService yfExmaineService, HttpServletRequest request) throws Exception {
			YfExmaineForm yfExmaineForm = new YfExmaineForm();
			yfExmaineForm.setProcessId(processInsId);
			// 审批列表
			List<YfExmaine> examineList = yfExmaineService.searchYfExmaine(yfExmaineForm, null);
			// 防止页面出错
			int resultSize = 0;
			if(examineList != null && !examineList.isEmpty()) {
				resultSize = examineList.size();
			}
			DisplayTagPageBean.getPageBean("examine", resultSize, 0, request);
			request.setAttribute("examineList", examineList);

		}
		
		/**
		 * 到达更新页面
		 * 
		 * @param mapping
		 * @param form
		 * @param request
		 * @param response
		 * @return ActionForward
		 * @throws Exception
		 */
		public ActionForward toUpdateIncYfProjectPlan(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
			log.debug("toUpdateIncOutsourceContract");
			String id = request.getParameter("id") == null ? "" : request.getParameter("id").toString();
			YfProjectPlanForm yfProjectPlanForm = (YfProjectPlanForm) form;
			yfProjectPlanForm.setId(id);
			yfProjectPlan = yfProjectPlanService.searchYfProjectPlan(yfProjectPlanForm,null).get(0);
			request.setAttribute(Constants.YFPROJECTPLAN, yfProjectPlan);
			request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
			if("2".equals(yfProjectPlan.getPlanType())){
				return mapping.findForward("change");
			}
			List planItems = yfProjectPlanService.getYfProjectPlanItems(yfProjectPlan.getId());
			request.setAttribute("workPlanList", planItems);
			request.setAttribute("workPlanCount", planItems == null ? 0 : planItems.size());

			return mapping.findForward(Constants.SUCCESS);
		}
		
		/**
		 * 更新
		 * 
		 * @param mapping
		 * @param form
		 * @param request
		 * @param response
		 * @return ActionForward
		 * @throws Exception
		 */
		public ActionForward updateIncYfProjectPlan(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
			log.debug("updateIncOutsourceContract");
			String id = request.getParameter("id") == null ? "" : request.getParameter("id").toString();
			YfProjectPlan yfProjectPlan = this.getYfProjectPlan(form);
			yfProjectPlan.setOperateid(CommonUtil.getCurrentUser(request).getId());
			yfProjectPlan.setCreateDate(new Date());
			this.yfProjectPlanService.updateObject(yfProjectPlan);
			yfProjectPlanService.deleteYfProjectPlanItems(yfProjectPlan.getId());
			addProjectWorkSheetsPlan(request,yfProjectPlan.getId());
			PrintWriter out = response.getWriter();
			out.print("<script>window.opener.document.location.reload(); self.close();</script>");
			return null;
		}
		
		
		
		public WorkFlowCommon getWorkFlowCommon() {
			return workFlowCommon;
		}

		public void setWorkFlowCommon(WorkFlowCommon workFlowCommon) {
			this.workFlowCommon = workFlowCommon;
		}

		public YfExmaineService getYfExmaineService() {
			return yfExmaineService;
		}

		public void setYfExmaineService(YfExmaineService yfExmaineService) {
			this.yfExmaineService = yfExmaineService;
		}
}
